package com.honey.mybatis.generator.mappper;

import com.honey.compilation.xml.XmlElement;
import com.honey.core.dbmapping.introspect.IntrospectSchemaColumn;
import com.honey.core.dbmapping.structure.Schema;
import com.honey.mybatis.generator.MybatisPlugin;

public class Cache extends AbstractMybatisMapper{

	public Cache(MybatisPlugin belongPlugin) {
		super(belongPlugin);
	}

	public void appendElement(XmlElement parent, Schema schema, IntrospectSchemaColumn introspectSchemaColumn ){
		parent.addNewLine();
		parent.addComments(
				"myBatis二级缓存配置, 只有在settings项中配置cacheEnabled=true才有效. 配置项意义如下:",
				"eviction : 缓存对象收回策略",
				"         LRU  – 最近最少使用的, 移除最长时间不被使用的对象.",
				"         FIFO – 先进先出, 按对象进入缓存的顺序来移除它们.",
				"         SOFT – 软引用, 移除基于垃圾回收器状态和软引用规则的对象.",
				"         WEAK – 弱引用, 更积极地移除基于垃圾收集器状态和弱引用规则的对象.",
				"flushInterval : 刷新缓存间隔时间.",
				"size : 缓存对象数量.",
				"readOnly : 只读缓存",
				"type :  缓存实现类,一般用于使用外部缓存,例如: oscache ehcache"
		);
		
		XmlElement cache = new XmlElement(parent,"cache")
		.addAttribute("eviction",mybatisPlugin.getCacheEviction())
		.addAttribute("flushInterval",mybatisPlugin.getCacheFlushInterval())
		.addAttribute("size",mybatisPlugin.getCacheSize())
		.addAttribute("readOnly",mybatisPlugin.getCacheReadOnly())
		;
		if( mybatisPlugin.getCacheType() != null){
			cache.addAttribute("type", mybatisPlugin.getCacheType());
		}
	}
}
